package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.InventoryCheck;
import com.ruoyi.pims.service.IInventoryCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存盘点记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-17
 */
@Controller
@RequestMapping("/pims/check")
public class InventoryCheckController extends BaseController
{
    private String prefix = "pims/check";

    @Autowired
    private IInventoryCheckService inventoryCheckService;

    @RequiresPermissions("pims:check:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/check";
    }

    /**
     * 查询库存盘点记录列表
     */
    @RequiresPermissions("pims:check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InventoryCheck inventoryCheck)
    {
        startPage();
        List<InventoryCheck> list = inventoryCheckService.selectInventoryCheckList(inventoryCheck);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点记录列表
     */
    @RequiresPermissions("pims:check:export")
    @Log(title = "库存盘点记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InventoryCheck inventoryCheck)
    {
        List<InventoryCheck> list = inventoryCheckService.selectInventoryCheckList(inventoryCheck);
        ExcelUtil<InventoryCheck> util = new ExcelUtil<InventoryCheck>(InventoryCheck.class);
        return util.exportExcel(list, "库存盘点记录数据");
    }

    /**
     * 新增库存盘点记录
     */
    @RequiresPermissions("pims:check:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存盘点记录
     */
    @RequiresPermissions("pims:check:add")
    @Log(title = "库存盘点记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.insertInventoryCheck(inventoryCheck));
    }

    /**
     * 修改库存盘点记录
     */
    @RequiresPermissions("pims:check:edit")
    @GetMapping("/edit/{checkId}")
    public String edit(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        InventoryCheck inventoryCheck = inventoryCheckService.selectInventoryCheckByCheckId(checkId);
        mmap.put("inventoryCheck", inventoryCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存盘点记录
     */
    @RequiresPermissions("pims:check:edit")
    @Log(title = "库存盘点记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.updateInventoryCheck(inventoryCheck));
    }

    /**
     * 删除库存盘点记录
     */
    @RequiresPermissions("pims:check:remove")
    @Log(title = "库存盘点记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(inventoryCheckService.deleteInventoryCheckByCheckIds(ids));
    }
}
